package com.chinasoft.exam.Config;

import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;

import javax.sql.DataSource;
//c2
public class MybatisConfig {
    @Bean
    //注入的是SqlSessionfactory
    public SqlSessionFactoryBean getSqlSessionFactory(@Autowired DataSource dataSource){
        SqlSessionFactoryBean ssfb = new SqlSessionFactoryBean();
        ssfb.setDataSource(dataSource);
        ssfb.setTypeAliasesPackage("com.chinasoft.exam.pojo");
        System.out.println("SqlSessionfactory");
        return ssfb;
    }
    @Bean
    //AccountMapper 会被注入容器
    public MapperScannerConfigurer getMapperScannerConfigurer(){
        MapperScannerConfigurer msc = new MapperScannerConfigurer();
        msc.setBasePackage("com.chinasoft.exam.mapper");

        return msc;
    }
}
